/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ar.edu.utn.frsf.ofa.javaee7.tp.ejemplo.ecompras.converters;

import ar.edu.utn.frsf.ofa.javaee7.tp.ejemplo.ecompras.modelo.Obra;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.inject.Inject;

/**
 *
 * @author Administrador
 */
@FacesConverter("ar.edu.utn.frsf.ofa.javaee7.ecompras.obraConverter")
public class ObraConverter implements Converter{

  
    @Inject
    ConverterHelper helper;
    
    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        System.out.println(" ver "+value);
        Obra aux = (Obra) helper.findById(Obra.class,value);
        System.out.println(" ver AUX anonononoononononononononoo"+((Obra)aux).getNombre());
        return aux;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        System.out.println(" ver AUX"+value+ " "+((Obra)value).getId());
        return Integer.toString(((Obra)value).getId());
    }
    
}
